package com.kgame5.xtank3d.effect.myemitters {
import kgame5.enginex.enum.Layer3DEnum;
import kgame5.k3d.core.math.Vector3D;
import kgame5.k3d.core.obj3d.node3d.Node3D;
import kgame5.k3d.pars.myflint.geom.Vector3DFlint;
import kgame5.k3d.pars.myflint.zones.MyDiscZone;
import kgame5.k3d.pars.myflint.zones.Zone3D;
import kgame5.kmath.MathDG;

import com.kgame5.xtank3d.effect.MyEmitter;
import com.kgame5.xtank3d.resource.ResourceManagerX;

/**
 * @author kk
 * 炮弹爆炸，炸出坦克的血液，这个用flint粒子系统做就很好实现
 * 注意这个md_g的位置要在0,0,0
 */
public class HurtBloodEmitter extends MyEmitter{
	public function HurtBloodEmitter(bp:Vector3D,tp:Vector3D) {
		//T.p("HurtBloodEmitter");
		var totalRange:int=64;//喷血液的区域
		var tankRadius:int=25;
		
		md_g.layerID = Layer3DEnum.LAYER_GROUNDMARK;
		
		var BloodR:int=15;//血块的大小
		
		
		bp.y=0;
		tp.y=0;
		
		var dir:Vector3D=tp.clone();
		dir.sub(bp);
		
		var pZone:Zone3D=new MyDiscZone(Vector3DFlint.ZERO,Vector3DFlint.AXISY,
											totalRange,tankRadius,
											dir,
											60);//角度幅度
		
		var count:int=MathDG.random(2,4);
		
		for(var i:int=0;i<count;i++){
			
			//碎片模型
			var md_chip:Node3D=ResourceManagerX.getInstance().getHurtBloodChip(BloodR);
			//Factory3D.CreateShadow(BloodR*2,"MyMc_Blood");
			
			var p:Vector3DFlint=pZone.getLocation();
			md_chip.posi.fill(p.x,p.y,p.z);
			
			//旋转
			md_chip.rotY=MathDG.random(0,3)*90;
			
			//缩放
			var scale:Number=MathDG.linearFunc(p.length,40,128)/40;//(128 + 10 - p.length) / 128;
			var scaleSpeed:Number=-0.05;
			
			md_chip.scale.mul(scale);
			md_chip.ti.hardVO.v3d_sv.fill(scaleSpeed,0,scaleSpeed);
			
			//生命
			md_chip.life=Math.abs(1/scaleSpeed);
			
			//--
			md_g.addChild(md_chip);
		}

		
		//T.p("暴血液结束");
	}
	

}//end of class
}
